import os
from leancloud import Object

AGMSHOP = Object.extend('AgmMapShop')

# AgmProduct = Object.extend('Agm_Product')

AgmProduct = Object.extend('Agm_Product_beta')

AgmFwCode = Object.extend('AgmFwCode')

AgmQrRecord = Object.extend('AgmQrRecord')

AgmSucGetJf = Object.extend('AgmSucGetJf')

AgmSeller = Object.extend('AgmSeller')

AgmSellRecord = Object.extend('AgmSellRecord')

AgmSellCount = Object.extend('AgmSellCount')

AgmSellVerifyProduct = Object.extend('AgmSellVerifyProduct')

WechatUser = Object.extend('WechatUser')

Cache_dict = Object.extend('Cache_dict')

WepaySuccess = Object.extend('WepaySuccess')

WechatKfOLRecord = Object.extend('WechatKfOLRecord')

WechatKfSwitch = Object.extend('WechatKfSwitch')

AgmKf = Object.extend('AgmKf')

AgmSellRegistLog = Object.extend('AgmSellRegistLog')

Log_Wechat_Message = Object.extend('Log_Wechat_Message')

Log_Wechat_Event = Object.extend('Log_Wechat_Event')

Wechat_Reply_Message = Object.extend('Wechat_Reply_Message')

WechatKfLog = Object.extend('WechatKfLog')

WechatShopOrder = Object.extend('WechatShopOrder')

AgmStaffReport = Object.extend('AgmStaffReport')

AgmStaffReview = Object.extend('AgmStaffReview')

AgmStaffRepair = Object.extend('AgmStaffRepair')

AgmStaffUser = Object.extend('AgmStaffUser')

selfCache = {}

ISLOCAL = os.environ.get('VIRTUAL_ENV', '').startswith('F:')

def getSelfCache(name, query, attr, *args):
    # if name in selfCache and not ISLOCAL:
    # print 'CacheKeys:', selfCache.keys()
    if name in selfCache:
        print 'selfCacheGet:%s' % name
        return selfCache[name]
    result = getattr(query, attr)(*args)
    selfCache[name] = result
    return result

def delcache():
    global selfCache
    selfCache = {}
    
def getQuerySelfCache(query, attr, *args):
    name = '%s:%s:%s:%s' % (query._query_class, query.dump(), attr, args)
    return getSelfCache(name, query, attr, *args)
